Switch

# Switch module

The Switch module takes care of basic input from things like buttons and switches and controls simple devices like fans and pumps.

## Configuration

Like TemperatureControl, there can be multiple Switch modules. All you need to do is give each module it's own name in the config file.

    switch.fan1.enable                        true
    switch.fan1.output_pin                    2.7
    etc ...

    switch.fan2.enable                        true
    switch.fan2.output_pin                    2.6
    etc ...

    switch.zplus10.enable                     true
    switch.zplus10.input_pin                  1.7
    switch.zplus10.output_on_command          G91G0Z10G90      # G90 and G91 switch to relative positioning then back to absolute

    etc ...

#### All options

Option | Example value | Explanation
--- | --- | ---

switch.module_name.enable | true | Create and enable a new Switch module if set to true. Switch modules use commands or pins as inputs, to send commands or switch pins as output. Note this module is very versatile and can be used to do many different things. Parameters that are not defined will be ignored.
switch.module_name.input_pin | `2.11` | When this pin becomes `high` the switch changes to the ON state, and when it becomes `low` the switch changes to the OFF state. ( see the `input_pin_behavior` option for more details }}
switch.module_name.input_pin_behavior | momentary | If set to `momentary` when the input pin becomes `high` the switch changes to the ON state, and when it becomes `low` the switch changes to the OFF state. If set to `toggle` the input pin toggles the switch's state between ON and OFF.
switch.module_name.input_on_command | M106 | Calling this command sets the switch ON
switch.module_name.input_off_command | M107 | Calling this command sets the switch OFF
switch.module_name.output_on_command | abort | This command is called when the switch changes to the ON state
switch.module_name.output_off_command | resume | This command is called when the switch changes to the OFF state
switch.module_name.output_pin | `2.6` | This pin will be set `low` when the switch is OFF, and `high` when the switch is ON
switch.module_name.output_type | pwm | Sets the type of output for the `output_pin`, if set to `digital` the pin can only be `low` or `high`, and if set to `pwm` the pin can be set to any PWM value between 0 and 255 using the S parameter, for example : `M106 S127`
switch.module_name.startup_state | false | Statup state of the switch. If set to `false` the module is initialized OFF, if set to `true` the module is initualized ON
switch.module_name.startup_value | 184 | Statup value of the switch if the `output_type` is `pwm`.
switch.module_name.max_pwm | 210 | Maximum value for the PWM output.

#### Startup State

The initial internal state of the switch at boot is set by the `startup_state` setting, which should be set to "true" or "false".

Also remember that individual pins can be inverted with a '`!`' ( see Pin Configuration ). Default is false.

There is also a `startup_value` setting that sets the default analog value used for pwm on an output pin. This value defaults to always on.

    switch.fan1.startup_state                 false
    switch.fan1.startup_value                 127

#### Input Pin

This setting will enable a pin that can be used to change the state of the switch. For example, a button can be configured that toggles the state of a fan. By default input_pin is set to "nc" which stands for "not connected".

There is also a behavior setting for the input pin. Currently the valid options are "`momentary`" (default) and "`toggle`".

The `toggle` behavior allows a momentary button to behave like an on-off toggle switch. If you are connecting a physical toggle switch you would probably want the behavior set to `momentary`.

    switch.fan1.input_pin                     1.7!
    switch.fan1.input_pin_behavior            toggle

#### Output Pin

Set this config value to drive an output pin based on the internal state of the Switch module. Remember that the pin can always be inverted with a '`!`' ( see Pin Configuration ).

    switch.fan1.output_pin                    2.7
    switch.fan1.output_type                  pwm             # pwm output settable with S parameter on the on command
    switch.fan1.max_pwm                     255               # sets the max pwm for this pin

To set an output pin to be non-pwm so it just turns on or off set output_type digital

    switch.psu.output_type                    digital           # just on or off
    switch.psu.output_pin                      1.30o!          # set to open drain, inverted to control an ATX PSON signal

#### Output type

There are two different output types : `digital` ( default ) and `pwm`

The only difference is that `pwm` will allow you to set PWM intensity via the `S` parameter to your G-codes.

#### Commands and Gcodes

There are also a set of config settings that allow the Switch module to both generate and react to Gcodes as necessary. The `input_on_command` is also able to read an S parameter to set an analog value for pwm over the output pin. This allows things like driving a fan at less than full speed or dimming an led.

    switch.fan1.input_on_command              M106     # any command that starts with this exact string turns this switch on
    switch.fan1.input_off_command             M107     # any command starting with this exact string turns off the switch

In addition to `input_on_command` and `input_off_command` there are also corresponding config settings `output_on_command` and `output_off_command`. Offhand, it seems unlikely that a single switch module would need to use both input_ and output_ commands.

## Examples

### Fan

This configuration will allow you to control a fan using the standard reprap G-codes for controlling a fan

This is already present in the default configuration file

    # Switch module for fan control
    switch.fan.enable                            true             #
    switch.fan.input_on_command                  M106             #
    switch.fan.input_off_command                 M107             #
    switch.fan.output_pin                        2.6              #
    switch.fan.output_type                       pwm              # pwm output settable with S parameter in the input_on_comand
    #switch.fan.max_pwm                           255              # set max pwm for the pin default is 255

### Power supply control

Here is how to control an ATX power supply's ON/OFF signal, so that your board can tell it to turn off when needed

    switch.psu.enable                            true             # turn atx on/off
    switch.psu.input_on_command                  M80              #
    switch.psu.input_off_command                 M81              #
    switch.psu.output_pin                        0.25o!           # open drain, inverted
    switch.psu.output_type                       digital          # on/off only

Note : this uses the PSON pin on the power supply, which should be open-drain, thus the `o` in `0.25o!`

### Pause when out of filament

    switch.filamentout.enable                true                     #
    switch.filamentout.input_pin             1.30^                    # pin where filemant out button is connected
    switch.filamentout.output_on_command     suspend                  # command

    switch.resume.enable                     true                     #
    switch.resume.input_pin                  1.31^                    # pin where resume button is connected
    switch.resume.output_on_command          resume                   # command

    after_suspend_gcode                      G91_G0E-5_G0Z10_G90_G0X-50Y-50        # gcode to run after suspend, retract then get head out of way
    before_resume_gcode                      G91_G1E1_G90                          # gcode to run after temp is reached but before resume - do a prime

### suspend and resume buttons

    switch.suspend.enable                true                     #
    switch.suspend.input_pin             1.30^                    # pin where pause button is connected
    switch.suspend.output_on_command     suspend                  # command

    switch.resume.enable                     true                     #
    switch.resume.input_pin                  1.31^                    # pin where resume button is connected
    switch.resume.output_on_command          resume                   # command

    after_suspend_gcode                      G91_G0E-5_G0Z10_G90_G0X-50Y-50        # gcode to run after suspend, retract then get head out of way
    before_resume_gcode                      G91_G1E1_G90                          # gcode to run after temp is reached but before resume - do a prime

page revision: 18, last edited: 21 Feb 2015 23:57
Edit Tags History Files Print Site tools + Options
Edit Sections Append Edit Meta Watchers Backlinks Page Source Parent Lock Page Rename Delete
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
See pages that link to and include this page.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.